package com.gec.controller;

import com.gec.dao.BookDao;
import com.gec.dao.BookDao1;
import com.gec.entity.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 修改图书的servlet
 *
 * 接受页面提交过来的数据 然后修改页面信息
 */
@WebServlet("/UpdateBookServlet")
public class UpdateBookServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //获取要修改的客房信息

        Book book = new Book();

        Integer id = Integer.parseInt(req.getParameter("id").trim());
        String name = req.getParameter("name");
        String author = req.getParameter("author");
        String price = req.getParameter("price");

        //将获取到的参数放到book对象中 统一管理
        book.setId(id);
        book.setName(name);
        book.setAuthor(author);
        book.setPrice(price);
        //调用dao方法执行修改
        BookDao bookDao = new BookDao();
        bookDao.updateBook(book);
        BookDao1 bookDao1 = new BookDao1();
        bookDao1.updateBook(book);
        //修改完毕  去显示页面
        resp.sendRedirect("BookListServlet");
    }
}
